<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{

    // 用户登录
    public function login(Request $request)
    {
        $body = $request->post();

        $token = Auth::guard('admin')
                     ->attempt($body);

        if (!$token) {
            abort(403, '登陆失败');
        }

        return [
            'data' => [
                'access_token' => $token,
                'token_type' => 'Bearer',
                'expires_in' => auth('admin')
                        ->factory()
                        ->getTTL() * 60,
            ],
        ];
    }
}
